#include <time.h>
#include "my_card_dqueue.h"
#include "base_card.h"

static int _card_order[TOTAL_CARD];
void init_card_order()
{
	int i;
	for(i = 0; i < TOTAL_CARD; i++)
		_card_order[i] = i;
}

static inline void swap(int *a,int *b)
{
	int tmp = *b;
	*b = *a;
	*a = tmp;
}



// shuffle _card_order, then push it into dqueue
Dqueue * card_shuffle()
{
	int i;
	const int max_swap = 8*TOTAL_CARD;
	
	init_card_order();
	
	//srand(time(NULL));
	for(i=0;i<max_swap;i++)
		swap( &(_card_order[rand()%TOTAL_CARD]), &(_card_order[rand()%TOTAL_CARD]));

#if 0
	for(i=0; i<TOTAL_CARD;i++)
		printf("%d ", _card_order[i]);
	printf("\n");
#endif
	Dqueue *ptr = createDqueue(TOTAL_CARD);
	
	for(i=0;i<TOTAL_CARD;i++)
		insertTailDqueue(ptr,get_card(_card_order[i]));
	
	return ptr;
}




void free_shuffle_card_order(Dqueue *ptr)
{
	freeDqueue(ptr);	
}




